<%@ page import="com.wl.shixun2.entity.Product" %>
<%@ page import="java.util.List" %>
<%@ page import="com.wl.shixun2.dao.ProductDAO" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    request.setCharacterEncoding("UTF-8");
%>
<html>
<head>
    <title>2350309097 万朗</title>
    <link rel="stylesheet" href="css/show.css" type="text/css">
</head>
<body>
<%
    String max=request.getParameter("max");
    String min=request.getParameter("min");
    String number=request.getParameter("number");
    String id=request.getParameter("id");
    String name=request.getParameter("name");
    String str="";
    List<Product> li=null;
    if(number!=null && !number.trim().isEmpty()){
        li=ProductDAO.findByNumber(number);
        str="根据产品号"+number+"查询到的记录是：";
    }
    else if(max!=null && !max.trim().isEmpty() && min!=null && !min.trim().isEmpty()){
        li= ProductDAO.findRecorder(min, max);
        str="价格在"+min+"至"+max+"之间的记录是：";
    }
    else if(id!=null && !id.trim().isEmpty()){
        try {
            long productId = Long.parseLong(id);
            li= ProductDAO.findById(productId);
            str="根据ID"+id+"查询到的记录是：";
        } catch(NumberFormatException e) {
            str="输入的ID格式不正确："+id;
        }
    }
    else if(name!=null && !name.trim().isEmpty()){
        li= ProductDAO.findByName(name);
        str="根据产品名称包含\""+name+"\"查询到的记录是：";
    }
%>
<P><%=str %></P>
<table width="600" border="1" align="center" cellpadding="2" cellspacing="0">
    <tr>
        <td align="center" bgcolor="#99FFFF">ID</td>
        <td align="center" bgcolor="#99FFFF">产品号</td>
        <td align="center" bgcolor="#99FFFF">名称</td>
        <td align="center" bgcolor="#99FFFF">生产日期</td>
        <td align="center" bgcolor="#99FFFF">价格</td>
        <td align="center" bgcolor="#99FFFF">操作</td>
    </tr>
    <% 
    if(li != null && !li.isEmpty()) {
        for(Product pro:li) {
    %>
    <tr>
        <td align="center"><%=pro.getId() %></td>
        <td align="center"><%=pro.getNumber() %></td>
        <td align="center"><%=pro.getName() %></td>
        <td align="center"><%=pro.getMadetime() != null ? pro.getMadetime().toString() : "" %></td>
        <td align="center"><%=pro.getPrice() %></td>
        <td align="center">
            <a class="edit-link" href="editProduct.jsp?id=<%=pro.getId()%>">编辑</a>
        </td>
    </tr>
    <% 
        } 
    } else {
    %>
    <tr>
        <td colspan="6" align="center">暂无数据</td>
    </tr>
    <%
    } 
    %>
</table>
<P align="center"><a href="index.jsp">返回</a>
</body>
</html>